// index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Component({
    data: {
        keyboard:{
            key:['1','2','3','4','5','6','7','8','9','.','0'],
            visible:true
        },
        money:{
            value:'',
            mark:'',
        }
    },
    methods: {
        // 显示/隐藏键盘
        keyboardShow:function(){
            this.setData({
                ["keyboard.visible"]:true
            });
        },
        keyboardHide:function(){
            this.setData({
                ["keyboard.visible"]:false
            });
        },
        // 输入数字或点
        keyboardAdd:function(event){
            // 获取按下值
            var item=event.currentTarget.dataset.item;
            // 当前的数字
            var moneyValue=this.data.money.value;
            // 限制小数点只能输入一个
            if (moneyValue.indexOf('.')>-1 && item=='.') return;
            // 限制最多只能输入9位
            if (moneyValue.length>9) return;
            // 叠加
            moneyValue+=item;
            this.setData({
                ["money.value"]:moneyValue
            });
        },
        // 删除
        keyboardDel:function(){
            // 当前的数字
            var moneyValue=this.data.money.value;
            // 删除最后一个
            if (moneyValue) {
                moneyValue = moneyValue.slice(0, -1);
            }
            this.setData({
                ["money.value"]:moneyValue
            });
        },
        // 付款
        keyboardPay:function(){
            // 当前的数字
            var moneyValue=this.data.money.value;
            var moneyMark=this.data.money.mark;
            wx.showModal({content:'付款：'+moneyValue});
            wx.showModal({content:'付款备注：'+moneyMark});
        },
        // 付款备注
        moneyMarkChange:function(event){
            var that=this;
            var value=event.detail.value;
            that.setData({
                ["money.mark"]:value
            });
            console.log('that.data.form',that.data.form);
        },
    },
})